<template>
    <Modal
            class-name="vertical-center-modal"
            v-model="modal"
            :width="80"
            :title="head_title">
        <div class="row">
            <div class="col-lg-12">
                <div class="card ">
                    <Form ref="formValidate" :model="info" action="javascript:void(0)">
                        <div class="row">
                            <div class="col-md-6">
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">姓名</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.name" placeholder="请输入姓名"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">手机号</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.phone" placeholder="请输入手机号"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">性别</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.sex" placeholder="请输入性别"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">国家</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.country" placeholder="请输入国家"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">公司名称</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.org" placeholder="请输入公司名称"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">职位</label>
                                        <div class="col-md-9">
                                            <!--<status-select class='thumb-search' :p-data="info.position" :p-name="'people_position'" :p-far='true'  @on-change='searchSelectPosition'></status-select>-->
                                            <Input v-model="info.position" placeholder="请输入职位"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">单位属性</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.industry" placeholder="请输入单位属性"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">地位</label>
                                        <div class="col-md-9">
                                            <status-select class='thumb-search' :p-data="info.standing" :p-name="'people_standing'" :p-far='true'  @on-change='searchSelectStanding'></status-select>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">主营业务</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.main_business" placeholder="请输入主营业务"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">在吉林投资情况</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.jl_des" placeholder="请输入在吉林投资情况"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">合作意向</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.will" placeholder="请输入合作意向"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">陪同人员组织机构</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.ptry_org" placeholder="请输入陪同人员组织机构"/>
                                        </div>
                                    </div>
                                </FormItem>

                            </div>
                            <div class="col-md-6">
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">到达航班车次</label>
                                        <div class="col-md-3">
                                            <status-select :p-data="info._arrive_station" p-name="station" @on-change="selectArriveStation"></status-select>
                                        </div>
                                        <div class="col-md-6">
                                            <Input v-model="info._arrive_num" placeholder="请输入到达航班车次"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">到达时间</label>
                                        <div class="col-md-9">
                                            <!--<DatePicker  :value='info.arrive_at' @on-change='timeChange($event,"arrive_at")' type="datetime" placeholder="到达时间" style="width: 200px"></DatePicker>-->
                                            <Input v-model="info.arrive_at" placeholder="请输入到达时间"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">离开航班车次</label>
                                        <div class="col-md-3">
                                            <status-select :p-data="info._leave_station" p-name="station" @on-change="selectLeaveStation"></status-select>
                                        </div>
                                        <div class="col-md-6">
                                            <Input v-model="info._leave_num" placeholder="请输入离开航班车次"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">离开时间</label>
                                        <div class="col-md-9">
                                            <!--<DatePicker :value='info.leave_at' @on-change='timeChange($event,"leave_at")' type="datetime" placeholder="离开时间" style="width: 200px"></DatePicker>-->
                                            <Input v-model="info.leave_at" placeholder="请输入离开时间"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">接送机车牌号</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.cart_no" placeholder="请输入接送机车牌号"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">入驻宾馆</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.hotel" placeholder="请输入入驻宾馆"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">房间号</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.room_no" placeholder="请输入房间号"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">入住时间</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.check_in_at" placeholder="请输入入住时间"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">退房时间</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.check_out_at" placeholder="请输入退房时间"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">邀请单位联系人</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.contacts" placeholder="请输入邀请单位联系人"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">邀请单位联系人电话</label>
                                        <div class="col-md-9">
                                            <Input v-model="info.contacts_phone" placeholder="请输入邀请单位联系人电话"/>
                                        </div>
                                    </div>
                                </FormItem>
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">对接洽谈会事宜</label>
                                        <div class="col-md-9">
                                            <c-input v-model="info.comment" placeholder="请输入对接洽谈会事宜" type="textarea" :maxlength="100" :limit="true"></c-input>
                                        </div>
                                    </div>
                                </FormItem>
                            </div>
                            <div class="col-md-6" v-if="role=='manager'&&type=='edit'">
                                <FormItem>
                                    <div class="row">
                                        <label slot='label' class="control-label text-right col-md-3">状态</label>
                                        <div class="col-md-9">
                                            <status-select class='thumb-search' :p-data="info.status" p-name="people_status" :p-far="true" @on-change='searchSelectStatus'></status-select>
                                        </div>
                                    </div>
                                </FormItem>
                            </div>
                        </div>
                    </Form>
                </div>
            </div>
        </div>
        <div slot="footer">
            <button class="btn btn-danger" type="button" @click='cancel'>取消</Button>
            <btn-submit class="btn btn-success" type="submit" :p-click="ok">确定</btn-submit>
        </div>
    </Modal>
</template>
<script>
    import serCustomer from '../../serves/api-customer'
    const setDataDef = {
        id:'',
        name:'',
        phone:'',
        org:'',
        position:'',
        industry:'',
        standing:'',
        main_business:'',
        jl_des:'',
        will:'',
        arrive_no:'',
        arrive_at:'',
        leave_at:'',
        leave_no:'',
        is_vip_port:'',
        cart_no:'',
        hotel:'',
        room_no:'',
        contacts:'',
        contacts_phone:'',
        comment:'',
        status:'',

        sex :'',
        check_in_at:'',
        check_out_at :'',
        ptry_org:'',

        _arrive_station :'',
        _arrive_num :'',
        _leave_station :'',
        _leave_num:'',
    };
    export default{
        props:{

        },
        data () {
            return {
                modal:false,
                type:'',
                role:'',
                info:{},
                file_book1:[],
                file_book2:[],
            }
        },
        computed:{
            head_title(){
                return this.type == 'edit' ? '编辑参会人员':'添加参会人员'
            },
        },
        methods: {
            async handleOpen(data){
                this.$set(this,'type',data._type=='edit'?'edit':'add');
                this.$set(this,'role',data._role);
                if(this.type=='edit'){
                    let res = await serCustomer.detail({
                        id:data.id
                    });
                    res.data._arrive_station = res.data.arrive_no.trim().split(' ')[0]||'';
                    res.data._arrive_num = res.data.arrive_no.trim().split(' ')[1]||'';
                    res.data._leave_station = res.data.leave_no.trim().split(' ')[0]||'';
                    res.data._leave_num = res.data.leave_no.trim().split(' ')[1]||'';
                    this.info = Object.assign({},setDataDef,res.data||{});
                }else{
                    this.info = Object.assign({},setDataDef);
                }
                this.$set(this,'modal',true);
            },
            cancel () {
                this.$emit('on-change',false);
                this.$set(this,'modal',false);
            },
            timeChange (value,key) {
                this.$set(this.info,key,value);
            },

            async ok () {
                if((!this.info._arrive_station&&!!this.info._arrive_num)||(!this.info._arrive_num&&!!this.info._arrive_station)){
                    this.$Message.warning('到达航班车次和到达时间需要同时填写');
                    return false;
                }
                if((!this.info._arrive_station&&!!this.info._arrive_num)||(!this.info._arrive_num&&!!this.info._arrive_station)){
                    this.$Message.warning('离开航班车次和离开时间需要同时填写');
                    return false;
                }
                let url = 'writeAdd';
                let data = {
                    name:this.info.name,
                    phone:this.info.phone,
                    org:this.info.org,
                    position:this.info.position,
                    industry:this.info.industry,
                    standing:this.info.standing,
                    main_business:this.info.main_business,
                    jl_des:this.info.jl_des,
                    will:this.info.will,
                    arrive_no:(this.info._arrive_station+' '+this.info._arrive_num).trim(),
                    arrive_at:this.info.arrive_at,
                    leave_at:this.info.leave_at,
                    leave_no:(this.info._leave_station+' '+this.info._leave_num).trim(),
                    is_vip_port:this.info.is_vip_port,
                    cart_no:this.info.cart_no,
                    hotel:this.info.hotel,
                    room_no:this.info.room_no,
                    contacts:this.info.contacts,
                    contacts_phone:this.info.contacts_phone,
                    comment:this.info.comment,

                    sex :this.info.sex,
                    check_in_at:this.info.check_in_at,
                    check_out_at :this.info.check_out_at,
                    ptry_org:this.info.ptry_org,
                };
                if(this.role=='manager'){
                    url = 'customerManagerAdd';
                    if(this.type=='edit'){
                        url = 'save';
                        data.id = this.info.id;
                        data.status = this.info.status;
                    }
                }else {
                    if(this.type=='edit'){
                        url = 'writeSave';
                        data.id = this.info.id;
                    }
                }
                let res = await serCustomer[url](data);
                if(res.code==1){
                    this.$Message.success(res.message);
                    this.$emit('on-change',true);
                    this.$set(this,'modal',false);
                    return true;
                }else{
                    this.$Message.error(res.message);
                    return false;
                }
            },
            searchSelectPosition(value){
                this.$set(this.info,'position',value);
            },
            searchSelectStanding(value){
                this.$set(this.info,'standing',value);
            },
            searchSelectStatus (value) {
                this.$set(this.info,'status',value);
            },
            selectArriveStation (value) {
                this.$set(this.info,'_arrive_station',value);
            },
            selectLeaveStation (value) {
                this.$set(this.info,'_leave_station',value);
            },
        },
        components:{
        }
    }
</script>